/*
 *  Shaders.h
 *  c_Render
 *
 *  Created by liao peterson on 3/16/10.
 *  Copyright 2010 uestc. All rights reserved.
 *
 */

#ifndef _SHADER_H__
#define _SHADER_H__

const char vertexShaderSrc[]=
"uniform mat4 u_mvpMatrix;		\n"
"uniform mat4 Model2World;		\n"
"attribute float drawMode;		\n"
"attribute vec4 a_camloc;		\n"
"attribute vec4 a_lamploc;		\n"
"attribute vec4 a_lamprgb;		\n"
"attribute vec4 a_position;		\n"
"attribute vec4 a_color;		\n"
"attribute vec4 a_normal;		\n"
"attribute vec2 a_texCoord;		\n"
"varying float	intensity;		\n"
"varying vec2	v_texCoord;		\n"
"varying vec3	v_lampdir;		\n"
"void main()					\n"
"{								\n"
"	if(drawMode==0.0){						"
"	gl_Position=u_mvpMatrix*a_position;		\n"
"	vec4 w_Position=Model2World*a_position;	\n"
"	v_lampdir=(a_lamploc-w_Position).xyz;		\n"
"   vec4 bnormal = a_normal; bnormal.w = 0.0;"
"	vec3 normal = normalize((Model2World * bnormal).xyz);"
"	intensity=pow(dot(normal,(normalize((a_camloc-w_Position).xyz+v_lampdir))/2.0),5.0)*50.0;			\n"
//"	intensity=(dot(normal,normalize(v_lampdir)))/pow(length(a_lamploc-w_Position),2.0)*1.0 + pow(dot(normal,(normalize((a_camloc-w_Position).xyz+v_lampdir))/2.0),1.0);			\n"
//"	intensity=(dot(normalize(normal),normalize(a_lamploc-w_Position)));"///pow(length(a_lamploc-w_Position),2.0)*1.0;"// + dot(normal,(normalize(a_camloc-w_Position)+v_lampdir)/2.0)*1.0;			\n"
"	}"
"	else if(drawMode==1.0){"
"		gl_Position=a_position;\n"
"		intensity = 0.45;"
"	}"
"	v_texCoord=a_texCoord;		\n"
"}";

const char fragmentShaderSrc[]=
"precision mediump float;		\n"
"varying vec2 v_texCoord;		\n"
//"varying vec4 v_lampdir;		\n"
"uniform sampler2D s_texture;	\n"
"varying float	intensity;		\n"
"void main()					\n"
"{								\n"
//"	lowp float intensity=dot(v_lampdir,texture2D(s_texture,v_texCoord));\n"
//"	gl_FragColor.r=intensity;gl_FragColor.g=intensity;gl_FragColor.b=intensity;			\n"
//"	gl_FragColor.r=dot(v_color,texture2D(s_texture,v_texCoord));		\n"
"	gl_FragColor=texture2D(s_texture,v_texCoord) * (intensity*2.0+0.1);		\n"
"   gl_FragColor.a=texture2D(s_texture,v_texCoord).a;"
"}";


#endif